﻿//创建时间: 2010-10-11
//创建作者: 李 城
//功能说明: 内容模型管理
//最后修改: 2010-10-11 修改 DeleteInfoById 使其调用 Idal.DeleteInfoById ，使其具有删除数据表的功能
using System;
using System.Collections.Generic;
using System.Text;


using TRPOP.CMS.Model;
using TRPOP.CMS.DALFactory;
using TRPOP.Common;

namespace TRPOP.CMS.Business
{
    public class ModelManage
    {

        private IModelDAL Idal;
        public ModelManage()
        {
            Idal = DataAccess.CreateModelDAL();
        }

        #region 结点数量限制的辅助方法
        /// <summary>
        /// 获取当前版本可获取的Model数目
        /// </summary>
        /// <param name="intSelect">要查询的结点数量</param>
        /// <returns></returns>
        public int GetLimitNums(int intSelect)
        {
            return TRPOP.CMS.Plugin.VersionLimit.GetLimitNums(intSelect, TRPOP.CMS.Plugin.VersionLimit.ContentModelLimit);
        }
        /// <summary>
        /// 是否溢出
        /// </summary>
        /// <returns></returns>
        public bool IsOverFlow()
        {
            if (TRPOP.CMS.Plugin.VersionLimit.ContentModelLimit == -1)
                return false;
            return GetListByCondition(0, "", "").Count >= TRPOP.CMS.Plugin.VersionLimit.ContentModelLimit;
        }
        #endregion


        #region 保存 Save
        ///	<summary>
        ///	保存
        ///	</summary>
        ///	<param name="ModelInfo"></param>
        ///	<returns>EnumSubmitResult</returns>
        public EnumSubmitResult Save(ModelInfo info)
        {
            return Idal.Save(info);
        }

        #endregion

        #region 获取实体 GetInfoById
        ///	<summary>
        ///	获取实体
        ///	</summary>
        ///	<param name="modelId"></param>
        ///	<returns>ModelInfo</returns>
        public ModelInfo GetInfoById(int id)
        {
            return Idal.GetInfoById(id);
        }
        #endregion

        #region 删除 DeleteInfoById
        ///	<summary>
        ///	删除
        ///	</summary>
        ///	<param name="id"></param>
        ///	<returns>EnumSubmitResult</returns>
        public EnumSubmitResult DeleteInfoById(int id)
        {
            return Idal.DeleteInfoById(id);
        }
        #endregion

        #region 删除 DeleteInfoByIds
        ///	<summary>
        ///	删除
        ///	</summary>
        ///	<param name="ids"></param>
        ///	<returns>EnumSubmitResult</returns>
        public EnumSubmitResult DeleteInfoByIds(string ids)
        {
            return Idal.DeleteInfoByIds(ids);
        }
        #endregion

        #region 自定义列表（无分页） GetListByCondition
        ///	<summary>
        ///	自定义列表（无分页）
        ///	</summary>
        ///	<param name="topn">前N条，为0时表示所有符合条件的</param>
        ///	<param name="condition">自定义条件，要以And开头</param>
        ///	<param name="orderby">排序，不需要Order by </param>
        ///	<returns>List<ModelInfo></returns>
        public List<ModelInfo> GetListByCondition(int topn, string condition, string orderby)
        {
            topn = GetLimitNums(topn);
            return Idal.GetListByCondition(topn, condition, orderby);
        }
        #endregion

        #region 自定义列表（分页） GetListByPager
        ///	<summary>
        ///	自定义列表（分页）
        ///	</summary>
        ///	<returns>List<ModelInfo></returns>
        public List<ModelInfo> GetListByPager(int pageNumber, int pageSize, string condition, string orderby, out int recordCount)
        {
            return Idal.GetListByPager(pageNumber, pageSize, condition, orderby, out  recordCount);
        }
        #endregion

        #region 获取最大Id
        /// <summary>
        /// 获取最大Id
        /// </summary>
        /// <returns></returns>
        public int GetMaxId()
        {
            return Idal.GetMaxId();
        }
        #endregion
    }
}
